package org.one.afternoon.mapper;

import org.apache.ibatis.annotations.*;
import org.one.afternoon.domain.Example;

import java.util.List;

@Mapper
public interface ExampleMapper {
    @Select("select * from example")
    List<Example> findAllOne();

    @Delete("delete from example where id=#{id}")
    void deleteUserById(Integer id);

    @Update("update example set attribute1=#{item.attribute1} , attribute2=#{item.attribute2} , attribute3=#{item.attribute3} , attribute4=#{item.attribute4} where id=#{item.id}")
    void updateOne(@Param("item") Example example);

    @Select({"<script>",
            "select * from example where 1=1",
            "<when test='item.attribute1!=null and item.attribute1!=\"\"'>and attribute1=#{item.attribute1}</when>",
            "<when test='item.attribute2!=null and item.attribute2!=\"\"'>and attribute2=#{item.attribute2}</when>",
            "<when test='item.attribute3!=null and item.attribute3!=\"\"'>and attribute3=#{item.attribute3}</when>",
            "<when test='item.attribute4!=null and item.attribute4!=\"\"'>and attribute4=#{item.attribute4}</when> </script>"})
    List<Example> findOne(@Param("item") Example example);

    @Insert("insert into example (attribute1,attribute2,attribute3,attribute4) values (#{attribute1},#{attribute2},#{attribute3},#{attribute4})")
    void insertOne(Example example);
}
